﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace davejk.Minecraft.ServerWrapper.Utils
{
    public static class SetupHelper
    {
        
        public static DirectoryCheckResponse CheckDirectories()
        {
            if (!Directory.Exists(AppBaseDirectory + "\\Minecraft"))
                Directory.CreateDirectory(AppBaseDirectory + "\\Minecraft");
            if (!Directory.Exists(AppBaseDirectory + "\\Backups"))
                Directory.CreateDirectory(AppBaseDirectory + "\\Backups");
            if (!Directory.Exists(AppBaseDirectory + "\\Data"))
            {
                System.Windows.Forms.DialogResult WarningResult = 
                    System.Windows.Forms.MessageBox.Show("The data directory is missing. Data files required for the program to " +
                    "function may not be present.\n\nReinstalling the application should fix this problem.", 
                    "Missing files", System.Windows.Forms.MessageBoxButtons.AbortRetryIgnore,
                    System.Windows.Forms.MessageBoxIcon.Error);
                switch (WarningResult)
                {
                    case System.Windows.Forms.DialogResult.Abort:
                        return DirectoryCheckResponse.ErrorAbort;
                    case System.Windows.Forms.DialogResult.Retry:
                        return DirectoryCheckResponse.ErrorRetry;
                    default:
                        return DirectoryCheckResponse.ErrorIgnore;
                }
            }
            return DirectoryCheckResponse.OK;
        }
        public enum DirectoryCheckResponse
        {
            OK,
            ErrorAbort,
            ErrorRetry,
            ErrorIgnore
        }

        public static bool IsServerInstalled()
        {
            return File.Exists(AppBaseDirectory + "\\Minecraft\\minecraft_server.jar");
        }

        public static string AppBaseDirectory {
            get {
                return Directory.GetParent(Path.GetDirectoryName(System.Reflection.Assembly.GetAssembly(typeof(Program)).Location)).Parent.FullName;
            }
        }

    }
}
